
// pages/content/setting.js
var app = getApp();
var rsa = require('../../utils/rsa.js');
var rsocket = require('../../utils/rsocket.js')
var voice = require('../../utils/voice.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ischeck:false,
    userstatus:100,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var openvoice = wx.getStorageSync('voice_open');
  
    const station = app.globalData.userstatus;//用户status  0未认证 2已认证 1审核中
    this.setData({
      userstatus: station,
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  //商户认证
  merchantValid:function(){
    const status = this.data.userstatus;
    if(status == 2){
      wx.showModal({
        title: '提示',
        content: '商户已审核，不需要重新认证',
        showCancel:false,
      })
      return;
    }
    if(status == 1){
      wx.showModal({
        title: '提示',
        content: '审核中，请耐心等待！',
        showCancel:false,
      })
     return;
    }
    wx.navigateTo({
      url: '/pages/userCenter/merIdentify',
    })
  },
  //语言播报
  playVoice:function(){
    // this.openWebSocket();
    // try {
    //   var value = wx.getStorageSync('vtoken')
    //   if (value) {
    //     voice.requestVoice(value)
    //   }
    // } catch (e) {
    //   voice.calVoice((err, res) => {
       
    //   })
    // }

    wx.getStorage({
      key: 'vtoken',
      success: function (res) {
        voice.requestVoice(res.data,'收款100元')
      },
      fail:function(res){
        voice.calVoice((err, res) => {
        })
      }
    })
  },
  //门店解绑
  invalidShop:function(){
    var shopnum = app.globalData.shoopnum;
    const setion = app.globalData.session;
    const mern = app.globalData.merchanN;
    const settion = app.globalData.session;
    wx.showLoading({
      title: '刷新中...',
      mask: true,
    })
    rsa.Cpic_fetchPost(rsa.SERVERPORT, { 'method': 'weixin.unbind', "seller_bn": shopnum, "seller_id": mern, 'session_id': settion}, (err, res) => {
      wx.hideLoading();
      if (err) {
        wx.showModal({
          title: '提示',
          content: err,
          showCancel: false,
        })
        return;
      }
      var rmsg = res.return_msg;
      wx.showModal({
        title: rmsg,
        content: '退出当前界面',
        showCancel: false,
        success: function (res) {
          wx.reLaunch({
            url: '/pages/index/index',
          })
        }
      })
    })
  },
 
  //语言播报选择
  switch1Change:function(e){
    console.log('switch1 发生 change 事件，携带值为', e.detail.value)
    const det = e.detail.value;
    wx.setStorage({
      key: 'voice_open',
      data: e.detail.value,
    })
    if(det){
      rsocket.openWebSocket();
    }
  },
  
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //静态码
  jtcodeAction: function () {
    wx.navigateTo({
      url: '/pages/content/jtm',
    })
  },
  //修改密码
  updateps:function(){
    wx.navigateTo({
      url: '/pages/content/updatepwd',
    })
  }
})